import logging

from common.config.config import logs_path


class DoLog:

    def ste_get_logger(self,level):
        # 申请记录器
        self.logger = logging.getLogger()
        # 设置日志编写等级
        self.logger.setLevel(level)

        # 申请写入的地方
        f=logging.FileHandler(logs_path,encoding='utf-8')
        # 控制台
        s=logging.StreamHandler()
        # 设置记录器所需要的格式对象
        ft=logging.Formatter('%(asctime)s - %(name)s - %(lineno)d- %(levelname)s - %(message)s')


        f.setFormatter(ft)
        s.setFormatter(ft)

        # 将记录器与写入的地方关联
        self.logger.addHandler(f)
        self.logger.addHandler(s)

        return self.logger



# if __name__ == '__main__':
#     logger = DoLog()
#     logger=logger.ste_get_logger(logging.INFO)
#     logger.log(logging.INFO,'自定义测试缺陷')